#include "sDrawContext.h"
#include "sEngine.h"

namespace sgui
{
namespace engine
{
	
bool sDrawContext::getClipRect() const
{
	return m_clipRect;
}

math::sRectf& sDrawContext::getRect()
{
	return m_rect;
}

math::sPointf& sDrawContext::getScroll()
{
	return m_scroll;
}
		
const math::sRectf& sDrawContext::getRect() const
{
	return m_rect;
}

const math::sPointf& sDrawContext::getScroll() const
{
	return m_scroll;
}

const math::sRectf& sDrawContext::getDrawRect() const
{
	return m_drawRect;
}

sDrawContext::sDrawContext(const sEngine& engine, const math::sRectf& rect, const sDrawContext* parentContext, bool clipRect) :
	m_rect(rect),
	m_drawRect(rect),
	m_parent(parentContext),
	m_clipRect(clipRect)
{
	if (m_parent)
	{
		m_drawRect = math::sRectf(
			rect.getPosition() + parentContext->getDrawRect().getPosition(), 
			rect.getSize()
		);	
		if (m_parent->getClipRect())
		{
			const math::sRectf& parent = m_parent->getDrawRect();
		
			if (m_drawRect.X < parent.X)
			{
				m_drawRect.W += m_drawRect.X - parent.X;
				m_drawRect.X = parent.X;
			}
			if (m_drawRect.Y < parent.Y)
			{
				m_drawRect.H += m_drawRect.Y - parent.Y;
				m_drawRect.Y = parent.Y;
			}
			if (m_drawRect.X + m_drawRect.W > parent.X + parent.W)
			{
				m_drawRect.W = parent.X + parent.W - m_drawRect.X;
			}
			if (m_drawRect.Y + m_drawRect.H > parent.Y + parent.H)
			{
				m_drawRect.H = parent.Y + parent.H - m_drawRect.Y;
			}
		}
	}
}

sDrawContext::sDrawContext(const sEngine& engine, const math::sRectf& rect, bool clipRect) :
	m_rect(rect),
	m_drawRect(rect),
	m_parent(NULL),
	m_clipRect(clipRect)
{

}
		
sDrawContext::~sDrawContext() 
{
	//
}

};
};
